export const base = 1920

export const rootValue = base / 10

export function rem2px(rem: number, root?: number) {
  if (!rem) return rem
  if (root) {
    return rem * root
  }
  return rem * rootValue
}

export function px2remPx(px: number) {
  const clientWidth =
    window.innerWidth || document.documentElement.clientWidth || document.body.clientWidth
  if (!clientWidth) return 0
  const fontSize = clientWidth / base
  return px * fontSize
}

export default function px2rem(px?: number, root?: number) {
  if (!px) return px
  if (root) {
    return `${px / root}rem`
  }
  return `${px / rootValue}rem`
}
